<input type="hidden" value="{$data.id}" id="id"/>
<input type="hidden" value="{$data.pid}" id="pid_v"/>
<div class="box box-warning">
    <div class="box-header with-border">
        <h3 class="box-title">
            <empty name="data.id">添加菜单<else />修改菜单</empty>
        </h3>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <form role="form">
            <!-- text input -->
            <div class="form-group">
                <label>菜单名称</label>
                <input id="name" type="text" value="{$data.name}" class="form-control" placeholder="">
            </div>
            <div class="form-group">
                <label>父菜单</label>
                <div>
                    <select id="pid" class="form-control select2 select2-hidden-accessible" style="width:100%;" tabindex="-1" aria-hidden="false"></select>
                </div>
            </div>
            <div class="form-group">
                <label>菜单链接</label>
                <input id="page_url" type="text" value="{$data.page_url}" class="form-control" placeholder="">
            </div>
            <div class="form-group">
                <label>图标样式</label>
                <input id="ico_class" type="text" value="{$data.ico_class}" class="form-control" placeholder="">
            </div>
            <div class="form-group">
                <label>是否可用</label>
                <div>
                    <select id="isUse" class="form-control select2 select2-hidden-accessible" style="width:100%;" tabindex="-1" aria-hidden="false">
                        <if condition="$data.isuse eq 1"><option value="1" selected="selected">可用</option><else /><option value="1">可用</option></if>
                        <if condition="$data.isuse eq 2"><option value="2" selected="selected">禁用</option><else /><option value="2">禁用</option></if>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label>排序</label>
                <empty name="data.sort">
                    <input id="sort" type="text" value="9999" class="form-control" placeholder="">
                    <else />
                    <input id="sort" type="text" value="{$data.sort}" class="form-control" placeholder="">
                </empty>
            </div>
            <div class="form-group">
                <label>消息框数量</label>
                <empty name="data.msg_num">
                    <input id="msg_num" type="text" value="0" class="form-control" placeholder="">
                    <else />
                    <input id="msg_num" type="text" value="{$data.msg_num}" class="form-control" placeholder="">
                </empty>
            </div>
            <div class="form-group">
                <label>消息框颜色（多个消息框用,号分隔）</label>
                <input id="msg_color" type="text" value="{$data.msg_color}" class="form-control" placeholder="">
            </div>
        </form>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        <button id="save" type="button" class="btn btn-info" style="width:120px;">保存</button>
        <button id="cancel" type="button" class="btn btn-default pull-right" style="width:90px;">取消</button>
    </div>
    <div class="overlay hidden">
        <i class="fa fa-refresh fa-spin"></i>
    </div>
</div>
<script type="text/javascript">
//模块名称定义
var moduleName = 'menu';

$(".select2").select2({
    minimumResultsForSearch: Infinity,
    language: "zh-CN"
});

//取消
$('#cancel').on('click', function() {
    window.location.href = '__ADMIN__#' + moduleName;
});

$('#save').on('click', function() {
    showLoad();
    $.ajax({
        type : "post",
        url : '__ADMIN__/' + moduleName + '/addoreditdata',
        dataType:"json",
        data: {
            id : $('#id').val()
            ,name : $('#name').val()
            ,pid : $('#pid').val()
            ,page_url : $('#page_url').val()
            ,ico_class : $('#ico_class').val()
            ,isUse : $('#isUse').val()
            ,sort : $('#sort').val()
            ,msg_num : $('#msg_num').val()
            ,msg_color : $('#msg_color').val()
        },
        success : function(msg) {
            //layer.msg(msg.msg);
            if (msg.code == 0)
                $.scojs_message(msg.msg, $.scojs_message.TYPE_OK);
            else
                $.scojs_message(msg.msg, $.scojs_message.TYPE_ERROR);
            hideLoad();
        }
    });
});

//读取父菜单
$(function() {
    $.ajax({
        type : "get",
        url : '__ADMIN__/' + moduleName + '/getParentMenu',
        dataType:"json",
        success : function(data) {
            var datas = [];
            var emp = new Object();
            emp.id = 0;
            emp.text = '一级菜单';
            datas.push(emp);

            for (var i = 0; i < data.length; i++) {
                var o = new Object();
                o.id = data[i].id;
                o.text = data[i].name;
                if (o.id == $('#pid_v').val()) {
                    o.selected = "selected";
                }
                datas.push(o);
            }
            $("#pid").select2({
                data:datas,
                minimumResultsForSearch: Infinity,
                language: "zh-CN"
            });
        }
    });
});
</script>